<!--
 * @Description: 
 * @Author: xiongkuobiao
 * @Date: 2023-02-02 12:15:34
 * @LastEditors: xiongkuobiao
 * @LastEditTime: 2023-02-02 16:38:07
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body></body>
<script>
    // 题目： 输入一组版本号，输出从大到小的排序
    // 输入： ['2.1.0.1', '0.402.1', '10.2.1', '5.1.2', '1.0.4.5']
    // 输出： ['10.2.1', '5.1.2', '2.1.0.1', '1.0.4.5', '0.402.1']
    let arr = ["2.1.0.1", "0.402.1", "10.2.1", "5.1.2", "1.0.4.5"];
    function paixu(arr) {
        return arr.sort((a, b) => {
            let i = 0;
            let left = a.split(".");
            let right = b.split(".");
            while (true) {
                if (left[i] == undefined || right[i] == undefined) {
                    return right.length - left.length;
                }
                if (left[i] == right[i]) continue;
                if (left[i] < right[i]) {
                    return right[i] - left[i];
                }
                i++;
            }
        });
    }
    console.log(paixu(arr));
</script>

</html>